<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>人事管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,type-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/xadmin.css">
     <script src="../../static/js/jquery-1.12.4.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/xadmin.js"></script>
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
          <input type="hidden" id="id" name="id"/>
          <div class="layui-form-item">
                <label for="L_typename" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="loginname" name="loginname" lay-verify="required" 
                        autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>昵称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" required="" lay-verify="required|nikename"
                        autocomplete="off" class="layui-input">
                </div>
				<div class="layui-form-mid layui-word-aux">
                    	昵称至少得3个字符！
                </div>
            </div>
	 		<div class="layui-form-item">
	 			<label class="layui-form-label">
                    <span class="x-red">*</span>状态
                </label>
                <div class="layui-input-inline">
		          <select name="status" id='status' lay-verify="required" >
		            <option value="">选择状态</option>
		            <option value="1">未审批</option>
		            <option value="2">正常</option>
		          </select>
		          </div>
	        </div>
            <div class="layui-form-item">
                <label for="L_update_time" class="layui-form-label">
                    创建时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="createdate" disabled="" class="layui-input">
                </div>
                
            </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="submit">
                &nbsp;&nbsp;提交&nbsp;&nbsp;
              </button>
          </div>
      </form>
    </div>
    <script>
      layui.use(['form','layer'], function(){
          $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;

      var data = JSON.parse(localStorage.getItem("data"));// JSno字符串转为对象
      $("#loginname").val(data.loginname);
      $("#username").val(data.username);
      $("#status").val(data.status);
      $("#createdate").val(data.createdate);
      $("#id").val(data.id);
      form.render();//重载表单
        //自定义验证规则
        form.verify({
          nikename: function(value){
            if(value.length < 2){
              return '昵称至少得2个字符啊';
            }
          }
        });

        //监听提交
        form.on('submit(add)', function(data){
            $.ajax({
                url: '../../updUser.action',
                type: 'post',
                data: data.field,
                success: function (data) {
                    if (data == 1) {
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //修改成功后刷新父界面
                            window.parent.location.reload();
                        });
                    }
                    else {
                        layer.alert("修改失败！")
                    }
                },
                error: function (e) {
                    layer.alert("error！提交失败！")
                },

            });
          return false;
        });
        
        
      });
      
      $("#loginname").keyup(function(){
      	var name=$(this).val();
          $.ajax({
              url:"../../checkName.action",
              type:"get",
              data:{"loginname":name},
              success:function(data){
               if(data==1){
                //开启提交按钮
              	$("#submit").removeClass("layui-btn-disabled").attr("disabled",false);
               }else {
              layer.msg('用户名已存在',{icon:7});
                //把提交按钮关闭
                $("#submit").addClass("layui-btn-disabled").attr("disabled",true)
                
               }

              },
              error:function(){
               alert("执行异常!");
              }
             })
      })
  </script>
   
  </body>

</html>